<template>
	<view>
		<view class="cardBox" v-if="loading==true">
			<view class="flex" style="margin-top: 10rpx;">
				{{$t("货物清单")}}
			</view>
			<view style="height: 10rpx;width: 100%;"></view>
		</view>

		<view class="buy_files" style="width: 95%;position: relative;z-index: 33;margin:0 auto;"
			v-if="orderDetail.orderInfo.goods_list">
			<view style="padding: 5px 10px;" class="downLoad" @click="downLoadFile(orderDetail.orderInfo.goods_list)">
				{{ orderDetail.orderInfo.goods_list.substring(orderDetail.orderInfo.goods_list.length, orderDetail.orderInfo.goods_list.length - 20) }}
			</view>
		</view>
		<view class="buy_files" style="width: 95%;position: relative;z-index: 33;margin:0 auto;"
			v-else-if="orderDetail.orderJoin.goods_list">
			<view style="padding: 5px 10px;" class="downLoad" @click="downLoadFile(orderDetail.orderJoin.goods_list)">
				{{ orderDetail.orderJoin.goods_list.substring(orderDetail.orderJoin.goods_list.length, orderDetail.orderJoin.goods_list.length - 20) }}
			</view>
		</view>

		<block v-if="orderDetail.orderInfo.status!=3&&orderDetail.orderInfo.status!=5&&orderDetail.orderInfo.close_status!=1&&orderDetail.orderInfo.terminate_status!=1">
			<view style="display: flex;width:90%;margin-left:5%;margin-top: 5%;" v-if="qrbtn">
				<view style="width: 50%;">
					<u-button @click="tongyi" style="" :custom-style="customStyle3" hover-class="none" type="primary">
						{{ $t('同意') }}
					</u-button>
				</view>
				<view style="width: 50%;">
					<u-button @click="jujue" style="" :custom-style="customStyle2" hover-class="none" type="primary">
						{{ $t('不同意') }}
					</u-button>
				</view>
			</view>
		</block>

	</view>
</template>


<script>
	import {
		HTTP_REQUEST_URL,
		HTTP_IMG_UTL,
		IMAGE_URL
	} from "@/config/app";

	export default {
		components: {

		},
		data() {
			return {
				//远程域名
				HTTP_IMG_UTL,
				HTTP_REQUEST_URL,
				IMAGE_URL,
				url: IMAGE_URL,

				//语言
				lang: this.$i18n.locale,

				customStyle2: {
					width: '255rpx',
					height: '83rpx',
					marginTop: '20rpx',
					background: '#ff2323',
					borderRadius: '56rpx'
				},
				customStyle3: {
					width: '255rpx',
					height: '83rpx',
					marginTop: '20rpx',
					background: '#18d62a',
					borderRadius: '56rpx'
				},
				subDisabled: false,
				loading: true,
				completion_list: '',
				orderDetail: {
					release_user: {},
					orderInfo:{
						goods_list:'',
					},
					orderJoin:{
						goods_list:'',
					}
				},
				qrbtn: false,
			}
		},
		onLoad(options) {
			this.order_id = options.order_id;
			this.join_order_id = options.join_order_id;
			this.getCooperationOrderDetail()

		},
		onReady() {
			uni.setNavigationBarTitle({ //自定义标题
				title: this.$t('确认货物清单')
			})
		},
		methods: {
			//合作订单详情
			getCooperationOrderDetail() {
				const that = this
				that.$u.api.order.getCooperationOrderDetail({
					id: that.join_order_id,
					lang: that.lang
				}).then(res => {
					that.orderDetail = res
					if(that.orderDetail.orderInfo.type == 'goods'&&that.orderDetail.orderInfo.is_goodslist==0&&that.orderDetail.role==1){
						that.qrbtn=true;
					}else if(that.orderDetail.orderInfo.type == 'goods'&&that.orderDetail.orderJoin.is_goodslist==0&&that.orderDetail.role==2){
						that.qrbtn=true;
					}else if(that.orderDetail.orderInfo.type == 'crossborder'&&that.orderDetail.orderJoin.is_goodslist==0&&that.orderDetail.role==2){
						that.qrbtn=true;
					}else if(that.orderDetail.orderInfo.type == 'transport'&&that.orderDetail.orderInfo.is_goodslist==0&&that.orderDetail.role==1&&(that.orderDetail.orderInfo.release_info.release_type==1||that.orderDetail.orderInfo.release_info.human_type==2)){
						that.qrbtn=true;
					}else if(that.orderDetail.orderInfo.type == 'transport'&&that.orderDetail.orderJoin.is_goodslist==0&&that.orderDetail.role==2&&(that.orderDetail.orderInfo.release_info.release_type==2||that.orderDetail.orderInfo.release_info.human_type==1)){
						that.qrbtn=true;
					}
				})
			},
			//下载文件
			downLoadFile(url) {
				const that = this
				uni.showLoading({
					title: "download...",
					mask: true
				})
				console.log('下载链接', url)
				var downloadTask = uni.downloadFile({
					url: this.IMAGE_URL+url,
					success(res) {
						uni.hideLoading()
						console.log('tempFilePath', res.tempFilePath)
						const tempFilePath = res.tempFilePath
						uni.openDocument({
							filePath: tempFilePath,
							showMenu: true,
							success: function(file) {
								console.log('file-success', file);
							}
						});
					},
				})
				downloadTask.onProgressUpdate(({
					progress,
					totalBytesWritten,
					totalBytesExpectedToWrite
				}) => {
					if (progress === 100) {
						downloadTask.offProgressUpdate();
					}
				})
			},

			tongyi() {
				const that = this
				if((that.orderDetail.orderInfo.goods_list)||(that.orderDetail.orderJoin.goods_list)){
					that.$u.api.order.confirmGoodsList({
						order_id: that.order_id,
						join_order_id: that.join_order_id,
						lang: that.lang,
						role: that.orderDetail.role,
					}).then(res => {
						uni.showModal({
							content: that.$t('操作成功'),
							showCancel: false,
							confirmText: that.$t('是'),
						})
						setTimeout(function() {
							uni.redirectTo({
								url: '/pages/ordering/orderDetail?id='+that.order_id+'&join_order_id='+that.join_order_id+'&status='+that.orderDetail.orderInfo.status+'&isDetail=true'
							  });
						}, 2000);
					})
				}else{
					uni.showModal({
						content: that.$t('操作成功'),
						showCancel: false,
						confirmText: that.$t('是'),
					})
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages/ordering/orderDetail?id='+that.order_id+'&join_order_id='+that.join_order_id+'&status='+that.orderDetail.orderInfo.status+'&isDetail=true'
						  });
					}, 2000);
				}
			},
			jujue() {
				const that = this
				uni.showModal({
					content: that.$t('操作成功'),
					showCancel: false,
					confirmText: that.$t('是'),
				})
				setTimeout(function() {
					uni.redirectTo({
						url: '/pages/ordering/orderDetail?id='+that.order_id+'&join_order_id='+that.join_order_id+'&status='+that.orderDetail.orderInfo.status+'&isDetail=true'
					  });
				}, 2000);
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/orderDetail.scss";

	.w3 {
		width: 33%;
		border: 1px solid #ccc;
		text-align: center;
		justify-content: center;
		align-items: center;
		font-size: 14rpx;
		display: flex;
		height: 50rpx;
		line-height: 50rpx;
	}

	.w9 {
		width: 90%;
		margin-left: 5%;
	}

	.w3 input {
		font-size: 14rpx;
	}
</style>